function gd(year, month, day) {
    return new Date(year, month - 1, parseInt(day)).getTime();
}

function gm(year, month) {
    return new Date(year, month - 1).getTime();
}

function gy(year) {
    return new Date(year).getTime();
}
var umonth = {1:"一月", 2:"二月", 3:"三月", 4:"四月", 5:"五月", 6:"六月", 7:"七月", 8:"八月", 9:"九月", 10:"十月", 11:"十一月", 12:"十二月"};

//------------------------------------------票务统计-----------------------------------------
var dataset = [
    {
        label: "核销数",
        data: [],
        color: "#1ab394",
        bars: {
            show: true,
            align: "center",
            barWidth: 24 * 60 * 60 * 600,
            lineWidth: 0
        }

    }, {
        label: "激活数",
        data: [],
        yaxis: 1,
        color: "#1C84C6",
        lines: {
            lineWidth:1,
                show: true,
                fill: true,
            fillColor: {
                colors: [{
                    opacity: 0.2
                }, {
                    opacity: 0.4
                }]
            }
        },
        splines: {
            show: false,
            tension: 0.6,
            lineWidth: 1,
            fill: 0.1
        },
    }
];

var options = {
    xaxis: {
        mode: "time",
        tickSize: [3, "day"],
        tickLength: 0,
        axisLabel: "Date",
        axisLabelUseCanvas: true,
        axisLabelFontSizePixels: 12,
        axisLabelFontFamily: 'Arial',
        axisLabelPadding: 10,
        color: "#d5d5d5"
    },
    yaxes: [
         {
            position: "left",
            clolor: "#d5d5d5",
            axisLabelUseCanvas: true,
            axisLabelFontSizePixels: 12,
            axisLabelFontFamily: ' Arial',
            axisLabelPadding: 67
        }
    ],
    legend: {
        noColumns: 1,
        labelBoxBorderColor: "#000000",
        position: "nw"
    },
    grid: {
        hoverable: false,
        borderWidth: 0
    }
};

//-----------------------------------讲解员统计-----------------------------------------
//讲解批次条形图
var narratorOption1 = {
    labels: [],
    series: []
};

var narratorOption2 = {
    stackBars: true,
    axisY: {
        labelInterpolationFnc: function(value) {
            return (value);
        }
    }
}
var getSum = (data) => {
    let sum = 0;
    for (const i of data) {
        sum += i;
    }
    return sum;
}

var setNarror = (data) => {
    _vm = window.statistical;
    _vm.narratorData.south_gat = getSum(data.south_gat);
    _vm.narratorData.north_gat = getSum(data.north_gat);
    _vm.narratorData.east_gat = getSum(data.east_gat);
    _vm.narratorData.main_gat = getSum(data.main_gat);
    _vm.narratorData.sum = getSum(data.east_gat) + getSum(data.south_gat) + getSum(data.north_gat)+getSum(data.main_gat);
}

var setNarratorFn = (data,type,interval = null) => {
    // return false;
    let label = [];
    if(type === 1) {
        for (let index = 1; index < data.south_gat.length + 1; index++) {
            if(index % 3 === 0) {
                if(index < 10) {
                    label.push('0' + index + '日')
                }else {
                    label.push(index + '日')
                }
                
            }else {
                label.push(' ')
            }
        }
        var style = 'stroke-width: 10px';
    }else if(type === 2) {
        for (let index = 1; index < 13; index++) {
            if(index < 10) {
                label.push('0' + index + '月')
            }else {
                label.push(index + '月')
            }
        }
        var style = 'stroke-width: 20px';
    }else if(type ===3) {
        let start = interval[0];
        let end = interval[1];
        for (let index = start; index < end + 1; index++) {
            label.push(index + '年')
        }
        var style = 'stroke-width: 20px';
    }
    narratorOption1.labels = label;
    narratorOption1.series.push(data.south_gat);
    narratorOption1.series.push(data.north_gat);
    narratorOption1.series.push(data.east_gat);
    narratorOption1.series.push(data.main_gat);
    setNarror(data);
    new Chartist.Bar("#ct-chart3", narratorOption1,narratorOption2).on('draw',function(data) {
        if(data.type === 'bar') {
            data.element.attr({
                style: style
            });
        }
    })

    var easeOutQuad = function (x, t, b, c, d) {
        return -c * (t /= d) * (t - 2) + b;
        };
        

    
}

//----------------------------停车统计--------------------------------
//实时停车数量曲线图
var setParkFn = (oneData,allData,type) => {
    let label = [];
    let usedData = [];
    let freeData = [];
    // let oneData = oneData;
    // let allData = allData;
    // let type = type;
    if(type === 3) {
        let data = allData;
        let sum_gat = [];
        for (const i in data.south_gat) {
            let one = [];
            one.push(data.south_gat[i][0]);
            let usedSum = data.south_gat[i][1] + data.north_gat[i][1];
            one.push(usedSum);
            let freeSum = data.south_gat[i][2] + data.north_gat[i][2];
            one.push(freeSum);
            sum_gat.push(one);
        }
        for (const item of sum_gat) {
            label.push(item[0]);
            usedData.push(item[1]);
            freeData.push(item[2]);
        }
    }else {
        let data = oneData;
        for (const item of data) {
            label.push(item[0]);
            usedData.push(item[1]);
            freeData.push(item[2]);
        }
    }
    var lineData = {
        labels: label,
        datasets: [
            {
                label: "停车数",
                backgroundColor: 'rgba(26,179,148,0.5)',
                borderColor: "rgba(26,179,148,0.7)",
                pointBackgroundColor: "rgba(26,179,148,1)",
                pointBorderColor: "#fff",
                data: usedData
            },{
                label: "空位数",
                backgroundColor: 'rgba(220, 220, 220, 0.5)',
                pointBorderColor: "#fff",
                data: freeData
            }
        ]
    };
    var ctx = document.getElementById("ct-chart6").getContext("2d");
    new Chart(ctx, {type: 'line', data: lineData});

    //停车数占比环形图
    let dataset = [];
    let sum1 = 0;
    let sum2 = 0;
    for (const i in allData.south_gat) {
        sum1 += allData.north_gat[i][1];
        sum2 += allData.south_gat[i][1]
    }
    dataset.push(sum1);
    dataset.push(sum2);
    let label2 = ["北门："+ sum1 + '次',"南门：" + sum2 + '次'];
    var doughnutData = {
        labels: label2,
        datasets: [{
            data: dataset,
            backgroundColor: ["rgb(26,179,148)","#79D2C0","rgb(220, 220, 220)"]
        }]
    } ;


    var doughnutOptions = {
        responsive: true
    };
    var ctx4 = document.getElementById("ct-chart7").getContext("2d");
    new Chart(ctx4, {type: 'doughnut', data: doughnutData, options:doughnutOptions});
};

var setVolunteerFn = (data,type,id=false) => {
    //条形图
    console.log(data);
    if(type === 1) {
        var x_ticks = [[1,umonth[1]],[2,umonth[2]],[3,umonth[3]],[4,umonth[4]],[5,umonth[5]],[6,umonth[6]],[7,umonth[7]],[8,umonth[8]],[9,umonth[9]],[10,umonth[10]],[11,umonth[11]],[12,umonth[12]]];
    }else {
        var x_ticks = [];
        for (const item of data.number_list) {
            let one = [];
            one.push(item[0]);
            one.push(item[0] + '年');
            x_ticks.push(one)
        }
    }
    var number_list = data.number_list;
    var barOptions = {
        series: {
            bars: {
                show: true,
                align: 'center',
                barWidth: 0.4,
                fill: true,
                fillColor: {
                    colors: [{
                        opacity: 0.8
                    }, {
                        opacity: 0.8
                    }]
                }
            }
        },
        xaxis: {
            tickDecimals: 0,
            ticks: x_ticks,
            autoscaleMargin: 0.01,
        },
        colors: ["#1ab394"],
        grid: {
            color: "#999999",
            hoverable: true,
            clickable: false,
            tickColor: "#D4D4D4",
            borderWidth:0,
            // show: false,
            labelMargin: 10,
            aboveData: false
        },
        legend: {
            show: false
        },
        tooltip: true,
    };
    var barData = {
        label: "数据",
        data: number_list
    };

    if(id) {
        let cid = "#newChartLeft" + id;
        $.plot($(cid), [barData], barOptions);
    }else {
        $.plot($("#flot-chart8"), [barData], barOptions);
    }
    // return false;

    //折线图
    let time_list = [];
    var barOptions = {
        series: {
            lines: {
                show: true,
                lineWidth: 2,
                fill: true,
                fillColor: {
                    colors: [{
                        opacity: 0.0
                    }, {
                        opacity: 0.0
                    }]
                }
            }
        },
        xaxis: {
            tickDecimals: 0,
            ticks: x_ticks
        },
        colors: ["#1ab394"],
        grid: {
            color: "#999999",
            hoverable: true,
            clickable: true,
            tickColor: "#D4D4D4",
            borderWidth:0
        },
        legend: {
            show: false
        },
        tooltip: true,
        tooltipOpts: {
            content: "x: %x, y: %y"
        }
    };
    var barData = {
        label: "bar",
        data: data.time_list
    };
    if(id) {
        let cid = "#newChartRight" + id;
        $.plot($(cid), [barData], barOptions);
    }else {
        $.plot($("#flot-chart9"), [barData], barOptions);
    }
};